{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append(\"..\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from finnlp.data_sources.social_media.finnhub_sentiment import Finnhub_Sentiment"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Config"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock = \"AAPL\"\n",
    "start_date = \"2023-01-16\"\n",
    "end_date = \"2023-02-19\"\n",
    "token = \"YOUR_FINNHUB_TOKEN\""
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### News_downloader"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "downloader = Finnhub_Sentiment({\"token\":token})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "75c33d2d1c984dbd959c21fdbaa437f4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "  0%|          | 0/9 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "downloader.download_sentiment(start_date,end_date,stock)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(477, 7)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "downloader.reddit.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>atTime</th>\n",
       "      <th>mention</th>\n",
       "      <th>positiveScore</th>\n",
       "      <th>negativeScore</th>\n",
       "      <th>positiveMention</th>\n",
       "      <th>negativeMention</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>2023-01-16 00:00:00</td>\n",
       "      <td>3</td>\n",
       "      <td>0.832384</td>\n",
       "      <td>-0.992166</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.087573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>2023-01-16 01:00:00</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.738558</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>2023-01-16 03:00:00</td>\n",
       "      <td>1</td>\n",
       "      <td>0.871529</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>2023-01-16 06:00:00</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.995663</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>2023-01-16 08:00:00</td>\n",
       "      <td>1</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.999917</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                atTime  mention  positiveScore  negativeScore  \\\n",
       "55 2023-01-16 00:00:00        3       0.832384      -0.992166   \n",
       "54 2023-01-16 01:00:00        1       0.000000      -0.738558   \n",
       "53 2023-01-16 03:00:00        1       0.871529       0.000000   \n",
       "52 2023-01-16 06:00:00        1       0.000000      -0.995663   \n",
       "51 2023-01-16 08:00:00        1       0.000000      -0.999917   \n",
       "\n",
       "    positiveMention  negativeMention     score  \n",
       "55                1                1 -0.087573  \n",
       "54                0                1 -1.000000  \n",
       "53                1                0  1.000000  \n",
       "52                0                1 -1.000000  \n",
       "51                0                1 -1.000000  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "downloader.reddit.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(571, 7)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "downloader.twitter.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>atTime</th>\n",
       "      <th>mention</th>\n",
       "      <th>positiveScore</th>\n",
       "      <th>negativeScore</th>\n",
       "      <th>positiveMention</th>\n",
       "      <th>negativeMention</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>2023-01-16 00:00:00</td>\n",
       "      <td>185</td>\n",
       "      <td>0.944244</td>\n",
       "      <td>-0.934446</td>\n",
       "      <td>104</td>\n",
       "      <td>56</td>\n",
       "      <td>0.304738</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>2023-01-16 01:00:00</td>\n",
       "      <td>175</td>\n",
       "      <td>0.957532</td>\n",
       "      <td>-0.934711</td>\n",
       "      <td>82</td>\n",
       "      <td>74</td>\n",
       "      <td>0.063303</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>2023-01-16 02:00:00</td>\n",
       "      <td>149</td>\n",
       "      <td>0.953763</td>\n",
       "      <td>-0.943735</td>\n",
       "      <td>67</td>\n",
       "      <td>71</td>\n",
       "      <td>-0.023705</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>2023-01-16 03:00:00</td>\n",
       "      <td>176</td>\n",
       "      <td>0.952826</td>\n",
       "      <td>-0.941478</td>\n",
       "      <td>98</td>\n",
       "      <td>58</td>\n",
       "      <td>0.261998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>2023-01-16 04:00:00</td>\n",
       "      <td>234</td>\n",
       "      <td>0.917571</td>\n",
       "      <td>-0.933355</td>\n",
       "      <td>119</td>\n",
       "      <td>94</td>\n",
       "      <td>0.108952</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                atTime  mention  positiveScore  negativeScore  \\\n",
       "63 2023-01-16 00:00:00      185       0.944244      -0.934446   \n",
       "62 2023-01-16 01:00:00      175       0.957532      -0.934711   \n",
       "61 2023-01-16 02:00:00      149       0.953763      -0.943735   \n",
       "60 2023-01-16 03:00:00      176       0.952826      -0.941478   \n",
       "59 2023-01-16 04:00:00      234       0.917571      -0.933355   \n",
       "\n",
       "    positiveMention  negativeMention     score  \n",
       "63              104               56  0.304738  \n",
       "62               82               74  0.063303  \n",
       "61               67               71 -0.023705  \n",
       "60               98               58  0.261998  \n",
       "59              119               94  0.108952  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "downloader.twitter.head(5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "finrl",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "afd6dc03c9be451573fc2885de79a969af6a24a159f11a3ead741ab7a9ff405f"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
